<?php
namespace Admin\Controller;
use Common\Controller\AdminbaseController;
class NewsTypeController extends AdminbaseController{
	
	function _initialize() {
		parent::_initialize();
	}
	
	function index(){
		$upperId = I("param.upperId", 0);
		$fcateName = I("param.cateName", '无');
		if($upperId==0){
			$result = $this->curl_http(C('news_url').'newsCategory/findNewsCategoryList?token='.$_SESSION["TOKEN"].'&cateLevel=1');
		}else{
			$result = $this->curl_http(C('news_url').'newsCategory/findNewsCategoryListByUpperId?token='.$_SESSION["TOKEN"].'&upperId='.$upperId);
		}
		$this->assign("fcateName", $fcateName);
		$this->assign("data", $result['ReturnData']['newsCategoryList']);
		$this->display();
	}
	
	function add(){
		$upperId = I("param.upperId", 0);
		$result = $this->curl_http(C('news_url').'newsCategory/findNewsCategoryListByUpperId?token='.$_SESSION["TOKEN"].'&upperId='.$upperId);
		$this->assign("data", $result['ReturnData']['newsCategoryList']);
		$this->display();
	}
	
	function add_post(){
		$name = I("param.cateName", "");
		$cateType = I("param.cateType", 1, "intval");
		$upperId = I("param.upperId", 0);
		$cateLevel = ($upperId !=0) ? 2 : 1;
		if(empty($name)){
			return $this->error("类型名称不能为空！");
		}
		$result = $this->curl_http(C('news_url').'newsCategory/addNewsCategory?token='.$_SESSION["TOKEN"], 'cateName='.$name.'&upperId='.$upperId.'&cateLevel='.$cateLevel);
		if($result['Success']){
			$this->success("添加成功！", U("Admin/NewsType/index"));
		}else{
			return $this->error($result['Message']);
		}
	}
	
	function edit(){
		$this->assign("cateId", I("param.cateId", 0));
		$this->assign("cateName", I("param.cateName", ""));
		$this->display();
	}
	
	function edit_post(){
		$name = I("param.cateName", "");
		if(empty($name)){
			return $this->error("类型名称不能为空！");
		}
		$typeId = I("param.cateId", 0);
		$result = $this->curl_http(C('news_url').'newsCategory/updateNewsCategory?token='.$_SESSION["TOKEN"], 'cateName='.$name.'&cateId='.$typeId);
		if($result['Success']){
			$this->success("修改成功！", U("Admin/NewsType/index"));
		}else{
			return $this->error($result['Message']);
		}
	}
	
	function delete(){
		$typeId = I("param.cateId",0);
		$result = $this->curl_http(C('news_url').'newsCategory/delNewsCategory?token='.$_SESSION["TOKEN"],'cateIds='.$typeId);
		if($result['Success']){
			$this->success("删除成功！", U("Admin/NewsType/index"));
		}else{
			return $this->error($result['Message']);
		}
	}

}